package com.gang.util_demo.service;

import com.gang.util_demo.enumpackage.SexEnum;
import com.gang.util_demo.pojo.Sex;
import org.springframework.util.ObjectUtils;

/**
 * 根据key拿到value值
 */
public class SexEnumService {

    public static void main(String[] args) {

        Sex sex = new Sex();
        sex.setCode(01);
        sex.setName("男");

        transfer(sex);
    }

    private static void transfer(Sex sex) {

        if (01 == sex.getCode()) {
            System.out.println("getBoyList");
        } else if (02 == sex.getCode()) {
            System.out.println("getGirlList");
        } else {
            System.out.println("getOtherlList");
        }

        // 通过枚举拿到值
        if (SexEnum.MAN.getCode() == sex.getCode()) {
            System.out.println("getBoyList");
        } else if (SexEnum.WOMEN.getCode() == sex.getCode()) {
            System.out.println("getGirlList");
        } else {
            System.out.println("getOtherlList");
        }

        String sexName = "";
        SexEnum sexEnum = SexEnum.getByCode(sex.getCode());
        if (!ObjectUtils.isEmpty(sexEnum)) {
            sexName = sexEnum.getName();
        }
        sex.setName(sexName);
        System.out.println(sex);

        //getBoyList
        //getBoyList
        //Sex(code=1, name=男)
    }

}
